package com.wnx.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.wnx.db.GoodsDao;
import com.wnx.entity.Goods;

public class MyGoodsAction extends ActionSupport {
	private int gid;
	private int uid;
	private int id;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	private String type;
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public int getGid() {
		return gid;
	}
	public void setGid(int gid) {
		this.gid = gid;
	}
	public int getUid() {
		return uid;
	}
	public void setUid(int uid) {
		this.uid = uid;
	}
	public String execute() {
		if(this.type.equals("upd")){
			Goods g = new Goods();
			g.setUid(this.uid);
			g.setId(this.id);
			GoodsDao gd = new GoodsDao();
			gd.updGoodsState(g);
			List<Goods> goods = gd.getGoodsByUid(g);
			if(goods.size()>0){
			HttpServletRequest request = ServletActionContext.getRequest();
			request.setAttribute("goods", goods);
			}
			return SUCCESS;
		}else if(this.type.equals("sel")){
		Goods g = new Goods();
		g.setUid(this.uid);
		GoodsDao gd = new GoodsDao();
		List<Goods> goods = gd.getGoodsByUid(g);
		if(goods.size()>0){
		HttpServletRequest request = ServletActionContext.getRequest();
		request.setAttribute("goods", goods);
		}
		return SUCCESS;
		}
		else{
			return ERROR;
		}
	}
}
